# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=miniupnpd
pkgver=2.3.7
pkgrel=0
pkgdesc="Lightweight UPnP IGD & PCP/NAT-PMP daemon"
url="https://miniupnp.tuxfamily.org/"
arch="all"
license="BSD-3-Clause"
install="$pkgname.post-install"
depends="uuidgen"
makedepends="bsd-compat-headers iptables-dev libnfnetlink-dev openssl-dev>3"
checkdepends="util-linux-dev"
subpackages="$pkgname-doc $pkgname-openrc
	$pkgname-iptables:_fwscripts:noarch
	$pkgname-ip6tables:_fwscripts:noarch
	"
source="http://miniupnp.free.fr/files/miniupnpd-$pkgver.tar.gz
	$pkgname.initd
"

# secfixes:
#   2.2.2-r0:
#     - CVE-2019-12107
#     - CVE-2019-12108
#     - CVE-2019-12109
#     - CVE-2019-12110
#     - CVE-2019-12111

build() {
	./configure \
		--vendorcfg \
		--leasefile \
		--ipv6 \
		--igd2
	make ISGITREPO=""
}

check() {
	make check ISGITREPO=""
}

package() {
	make PREFIX="$pkgdir/" ISGITREPO="" install
	install -m755 -D "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/$pkgname
}

_fwscripts() {
	depends=
	local _tables=${subpkgname#$pkgname-}
	pkgdesc="$_tables scripts for $pkgname"
	install_if="$pkgname=$pkgver-r$pkgrel $_tables"
	amove	/etc/miniupnpd/${_tables}_init.sh \
		/etc/miniupnpd/${_tables}_removeall.sh
}

sha512sums="
7409bd6777c2a572ea501d47be604d9b09c09b1451c0f4150acd2313e3a5b4f7f3567559324a6c634c11a2b7c0ff56886a85217d1b056d5402916d0a8a3408e8  miniupnpd-2.3.7.tar.gz
3619d66b5d27369e9ae368f189fc4f4e25a803b460a954f47fd749195755bda8e828fbaa4e04ffc980aa72078f790d41a313c2ab7d0de7d4c284251a577b7a90  miniupnpd.initd
"
